<template>
	<!-- 隐患整改下发流程页面 -->
	<view class="workApply-container" :style="{ height: `${windowHeight}px` }">
		<!-- 基础表单校验 -->
		<uni-forms ref="valiForm" :rules="rules" :modelValue="valiFormData" border class="view-form">
			<uni-forms-item label="整改订单编号：" name="orderNumber">
				<uni-easyinput v-model="form.orderNumber" disabled placeholder="请输入内容"></uni-easyinput>
			</uni-forms-item>

			<uni-forms-item label="计划完成时间：" name="planRectificationTime">
				<uni-easyinput v-model="form.planRectificationTime" disabled placeholder="请输入内容"></uni-easyinput>
			</uni-forms-item>

			<uni-forms-item label="整改措施：" name="rectificationMeasures">
				<uni-easyinput v-model="form.rectificationMeasures" disabled placeholder="请输入内容"></uni-easyinput>
			</uni-forms-item>
			<uni-forms-item label="状态：" name="hiddenDangerStatus">
				<view class="view-input">{{formatTaskStatus(form.hiddenDangerStatus)}}</view>
				<!-- <uni-easyinput v-model="formatTaskStatus(form.hiddenDangerStatus)" disabled placeholder="请输入内容"></uni-easyinput> -->
			</uni-forms-item>
			<uni-forms-item label="整改单位：" name="hiddenDangerUnitName">
				<uni-easyinput v-model="form.hiddenDangerUnitName" disabled placeholder="请输入内容"></uni-easyinput>
			</uni-forms-item>
			<uni-forms-item label="公司级整改人：" name="companyHeadName">
				<uni-easyinput v-model="form.companyHeadName" disabled placeholder="请输入内容"></uni-easyinput>
			</uni-forms-item>
			<uni-forms-item label="整改部门：" name="hiddenDangerDeptName">
				<uni-easyinput v-model="form.hiddenDangerDeptName" disabled placeholder="请输入内容"></uni-easyinput>
			</uni-forms-item>
			<uni-forms-item label="部门级整改人：" name="departmentHeadName">
				<uni-easyinput v-model="form.departmentHeadName" disabled placeholder="请输入内容"></uni-easyinput>
			</uni-forms-item>
			<uni-forms-item label="整改直接责任人：" name="personDirectlyResponsibleName">
				<uni-easyinput v-model="form.personDirectlyResponsibleName" disabled
					placeholder="请输入内容"></uni-easyinput>
			</uni-forms-item>
			<uni-forms-item label="计划整改金额 (万元)：" name="planRectificationMoney">
				<uni-easyinput v-model="form.planRectificationMoney" disabled placeholder="请输入内容"></uni-easyinput>
			</uni-forms-item>


			<uni-forms-item label="审批操作：" required name="approveStatus">
				<uni-data-checkbox v-model="valiFormData.approveStatus"
					:localdata="whetherDutyOption"></uni-data-checkbox>
			</uni-forms-item>
			<uni-forms-item label="审批意见：" required name="approveRemark">
				<uni-easyinput type="textarea" v-model="valiFormData.approveRemark" placeholder="请输入内容"></uni-easyinput>

			</uni-forms-item>

		</uni-forms>

		<button type="primary" @click="submit('valiForm')" class="submit-btn">
			确认
		</button>


	</view>
</template>

<script>
	import widowHeightMixins from "@/mixins/widowHeightMixins.js";
	import {
		distributeRect
	} from "@/api/hiddenTrouble/rectification.js";

	export default {
		mixins: [widowHeightMixins],
		components: {

		},
		onLoad(e) {
			// console.log(e, "e");
			const eventChannel = this.getOpenerEventChannel()
			eventChannel.on('acceptDataFromOpenedPage', (data) => {
				this.valiFormData.id = data.checkId
				this.rowData = data.rowData
				this.form = data.rowData
				console.log("接受", data)
				
				if( data.rowData.hiddenDangerStatus == 3){
					// 动态设置标题
					uni.setNavigationBarTitle({
						title: `隐患整改--计划审批`,
					});
				}else if(data.rowData.hiddenDangerStatus == 5){
					// 动态设置标题
					uni.setNavigationBarTitle({
						title: `隐患整改--反馈`,
					});
				}
		
			});
	
		},
		data() {
			return {
				whetherDutyOption: [{
					"value": 1,
					"text": "通过"
				}, {
					"value": 2,
					"text": "驳回"
				}, ],

				form: {},
				rules: {},
				rowData: {},
				valiFormData: {}
			}
		},
		methods: {
			//格式化状态
			formatTaskStatus(val) {
				if (val == 1) {
					return "计划未发中";
				} else if (val == 2) {
					return "计划下发中";
				} else if (val == 3) {
					return "计划审批中";
				} else if (val == 4) {
					return "反馈中";
				} else if (val == 5) {
					return "反馈审批中";
				} else if (val == 1001) {
					return "完成";
				}
			},
			//提交
			submit() {
				this.$refs.valiForm.validate().then(res => {
					console.log('表单数据信息：', res);
					this.valiFormData.id = this.rowData.id;
					distributeRect(this.valiFormData).then((res) => {
						console.log("res==", res)
						uni.showToast({
							title: '审批成功',
							duration: 2000
						})
						uni.navigateTo({
							url: "/pages/trouble/index",
							success: (res) => {
								res.eventChannel.emit('acceptDataFromOpenerPage', {
									page: 'manage',
									title: '计划反馈'
								})
							}
						})
					})
				}).catch(err => {
					console.log('表单错误信息：', err);
				})

			}
		}
	}
</script>

<style lang="scss" scoped>
	.workApply-container {
		padding: 20rpx;
		background-color: #fff;
		overflow-y: auto;

		.view-form {}

		::v-deep {

			.view-input {
				display: flex;
				align-items: center;
				width: auto;
				position: relative;
				overflow: hidden;
				flex: 1;
				line-height: 1;
				font-size: 14px;
				height: 35px;
				padding-left: 10px;
				border-color: rgb(229, 229, 229);
				    background-color: rgb(247, 246, 246);
			}

			.uni-easyinput {
				border: 1px solid #e5e5e5;

				.is-disabled {
					color: #646464;
				}
			}

			.uni-forms-item--border {
				border-top: 0 solid #000;
				border-bottom: 2rpx solid #e8eaec;
			}

			.uni-forms-item__label {
				width: 40% !important;
			}

			.submit-btn {
				margin-top: 30rpx;
				background: #137ee9;
				border-radius: 10rpx;
			}
		}
	}
</style>